// @ts-ignore 运营后台登录
export async function execute(http_message) {
    // {"username":"123123","password":"123123","autoLogin":true,"code":"login","type":"account"}
    let body = http_message["body"];
    if (body["username"] === undefined) {
        return HttpResUtils.err_msg("账号不能为空");
    }
    if (body["password"] === undefined) {
        return HttpResUtils.err_msg("密码不能为空");
    }
    // 查询游戏账号
    let accounts = await G.Accounts.query_accounts_db(body["username"]);
    if (accounts.length > 0) {
        let accounts_json = JSON.parse(accounts);
        if (body["password"] !== accounts_json["password"]) {
            return HttpResUtils.err_msg("密码错误")
        }
        // 删除之前缓存的token
        if(_AdminUserTokenCache.has(accounts_json["username"])){
            _AdminTokenUserCache.delete(_AdminUserTokenCache.get(accounts_json["username"]));
        }
        // 缓存新的token
        let token = _jwt_.gen(accounts_json["username"], `${accounts_json["id"]}`);
        _AdminTokenUserCache.set(token,accounts_json["username"]);
        _AdminUserTokenCache.set(accounts_json["username"],token);
        return HttpResUtils.ok(token);
    } else {
        return HttpResUtils.err_msg("账号不存在");
    }
}